package com.atguigu.spzx.cloud.order.service.impl;

import com.atguigu.spzx.cloud.order.entity.Order;
import com.atguigu.spzx.cloud.order.entity.User;
import com.atguigu.spzx.cloud.order.mapper.OrderMapper;
import com.atguigu.spzx.cloud.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;


//todo 使用注册中心拉取 [loadbalancer自带负载均衡注册]
//@Service
public class OrderServiceImpl配合负载均衡使用 {

    //@Autowired
    private OrderMapper orderMapper ;

    //@Autowired
    private RestTemplate restTemplate;

    //@Override
    public Order findOrderByOrderId(Long orderId) {
        Order order = orderMapper.findOrderByOrderId(orderId);
        User user = restTemplate.getForObject("http://spzx-cloud-user/api/user/findUserByUserId/"+order.getUserId(), User.class);
        order.setUser(user);
        return order;
    }
}